package com.cskaoyan.wordmemorize.controller.admin;

import com.cskaoyan.wordmemorize.auth.SaAdminCheckPermission;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.admin.VocBookDTO;
import com.cskaoyan.wordmemorize.request.BatchDeleteCommand;
import com.cskaoyan.wordmemorize.request.VocBookCommand;
import com.cskaoyan.wordmemorize.request.VocBookPageRequest;
import com.cskaoyan.wordmemorize.service.VocBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("admin/voc")
public class VocBookController {
    @Autowired
    private VocBookService vocBookService;


    //@SaAdminCheckPermission("super-admin")
    @PostMapping("book")
    public Result addVocBook(@RequestBody VocBookCommand command){
        vocBookService.addVocBook(command);
        return Result.ok();
    }

   // @SaAdminCheckPermission("super-admin")
    @PutMapping("book")
    public Result updateVocBook(@RequestBody VocBookCommand command){
        System.out.println("command.getId() = " + command.getId());
        vocBookService.updateVocBook(command);
        return Result.ok();
    }

  //  @SaAdminCheckPermission("super-admin")
    @GetMapping("book/list")
    public Result<PageDTO<VocBookDTO>> getBookPage(VocBookPageRequest pageQuery){
        PageDTO<VocBookDTO> bookPage = vocBookService.getBookPage(pageQuery);

        return Result.ok(bookPage);
    }

  //  @SaAdminCheckPermission("super-admin")
    @DeleteMapping("book/{bookId}")
    public Result deleteVocBook(@PathVariable("bookId") Long bookId){
        vocBookService.deleteVocBook(bookId);
        return Result.ok();
    }

    //@SaAdminCheckPermission("super-admin")
    @DeleteMapping("books")
    public Result deleteBookCategory(@RequestBody BatchDeleteCommand command){
        vocBookService.deleteVocBooks(command);
        return Result.ok();
    }
}
